package com.wzh.yebServe.controller;

import com.wzh.yebServe.pojo.Position;
import com.wzh.yebServe.pojo.ResultBean;
import com.wzh.yebServe.service.IPositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * @Author wzh
 * @create 2022/11/14 21:00
 * @Description:
 */
@Api(tags = "PositionController  职位信息管理接口")
@RestController
@RequestMapping("/system/basic/pos")
public class PositionController {
    @Autowired
    private IPositionService iPositionService;


    @ApiOperation(value = "获取所有职位的信息")
    @GetMapping("/")
    public List<Position> getAllPositions(){
        return iPositionService.list();
    }


    @ApiOperation(value = "添加职位信息")
    @PostMapping("/")
    public ResultBean addPosition(@RequestBody Position position){
        position.setCreateDate(LocalDateTime.now());
        boolean save = iPositionService.save(position);
        if (save){
            return ResultBean.success("添加成功");
        }else
            return ResultBean.error("添加失败，请稍后重试");
    }


    @ApiOperation(value = "更新职位信息")
    @PutMapping("/")
    public ResultBean updatePosition(@RequestBody Position position){
        boolean b = iPositionService.updateById(position);
        if (b){
            return ResultBean.success("更新成功");
        }else
            return ResultBean.error("更新失败");

    }


    @ApiOperation(value = "删除某个职位")
    @DeleteMapping("/{id}")
    public ResultBean deletePosition(@PathVariable  Integer id){
        boolean b = iPositionService.removeById(id);
        if (b) {
            return ResultBean.success("删除成功");
        }else
            return ResultBean.error("删除失败");
    }


       @ApiOperation("批量删除")
       @DeleteMapping("/")
        public ResultBean deletePositionsByids(Integer[] ids){
           boolean b = iPositionService.removeByIds(Arrays.asList(ids));
           if (b) {
               return ResultBean.success("删除成功");
           }
           else
               return ResultBean.error("删除失败");

       }


}
